package com.wellness.commons.paging;

public class Limit {

    private static int DEFAULT_PAGE_SIZE = 20;

    private int pageSize;

    private int pageNo;

    private int offset;

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public static Limit build(int pageNo, int pageSize) {
        if (pageNo <= 0) {
            pageNo = 1;
        }
        if (pageSize <= 0) {
            pageSize = DEFAULT_PAGE_SIZE;
        }
        Limit limit = new Limit();
        limit.setOffset((pageNo - 1) * pageSize);
        limit.setPageNo(pageNo);
        limit.setPageSize(pageSize);
        return limit;
    }
}
